from flask_login import UserMixin

from Config import db, login_manager
from model import s_admin


@login_manager.user_loader
def user_loader(id):
    return Admin.query.filter_by(id=id).first()


# 管理员账户只能通过数据库直接添加数据
class Admin(db.Model, UserMixin):
    __tablename__ = 'admin'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(30), unique=False)
    password = db.Column(db.String(30), unique=False)
    s_admin_id = db.Column(db.Integer, db.ForeignKey('S_admin.id'), default=1)
    s_admin = db.relationship('S_Admin')

    def get_id(self):
        return self.id


if __name__ == '__main__':
    db.create_all()
